<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="group9.User" %>
<%@ page import="group9.UserStory" %>
<%@ page import="group9.PMF" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<link rel="stylesheet" type="text/css" href="styles.css" title="Style 1"/>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Login</title>
	</head>
	
	<!-- Claudio Herreros, Dylan James, Tyler Berg -->
	
	<body>
			<%
				User user = (User) request.getSession().getAttribute("User");
	
				PersistenceManager pm = PMF.get().getPersistenceManager();
				user = (User) pm.getObjectById(User.class, user.getKey());
	
				if (user == null)
				{
					response.sendRedirect("index.html");
					return;
				}
			
				LinkedList<UserStory> unestimated = new LinkedList<UserStory>();
				List<Boolean> estimated = user.getEstimated();
				List<Key> storyKeys = user.getEstUserStories();
			
				for (int i = 0; i<estimated.size(); i++)
				{
					if(!estimated.get(i))
						unestimated.add((UserStory)pm.getObjectById(UserStory.class, storyKeys.get(i)));
				}
			
				pm.close();
			%>
	<h1>Login</h1>
	<hr/>
	<h2>Unestimated User Stories</h2>
		<% 
			if (estimated.isEmpty())
			{
		%>
				<div align="center" class="Info">You have no User Stories that require estimates.</div>
		<%
			}
			else
			{
		%>
				<form action="/SignIn" method="post">
					<table align="center"  border="0" cellspacing="0" cellpadding="5">
						<tr>
							<td>
								<span align="center"><strong>User Story</strong></span>
							</td>
							<td>
								<span align="center"><strong>Actions</strong></span>
							</td>
						</tr>
						<%
						
						for (int i = 0; i < unestimated.size(); i++)
						{
							UserStory us = unestimated.get(i);
						%>
						<tr>
							<td>
								<span class="BoxLabel"><%= us.getTitle() %></span>
							</td>
							<td>
								<span class="Field">
									<a href="ViewUserStory.jsp" onclick="<%session.setAttribute("UserStory",us);%>">Edit</a>
								</span>
							</td>
						<%
						}
						%>
								</tr>
						<%
							}
						
						pm.close();
						%>
					</table>
				</form>
		<hr/>
		<a href="home.jsp">Back!</a>
	</body>
</html>
